package com.xiaoming.backend.controller;

import com.xiaoming.backend.dto.request.FacilityRequest;
import com.xiaoming.backend.entity.orm.Facility;
import com.xiaoming.backend.service.IFacilityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/facility")
@RequiredArgsConstructor
@PreAuthorize("@securityService.checkInstitution(#institutionId)")
@Tag(name = "FacilityController", description = "机构实例")
public class FacilityController {
    private final IFacilityService facilityService;
    @PostMapping("/register")
    @Operation(summary = "registerFacility", description = "新增机构")
    public ResponseEntity<?> registerFacility(@RequestBody FacilityRequest facilityRequest){
        facilityService.registerFacility(facilityRequest);
        return ResponseEntity.ok("");
    }

    @PostMapping("/get")
    @Operation(summary = "getFacility", description = "获取对应的类型的机构")
    public ResponseEntity<?> getFacility(@RequestBody FacilityRequest facilityRequest){
        List<Facility> facility = facilityService.getFacility(facilityRequest.getFacilityType());
        return ResponseEntity.ok(facility);
    }
}
